package com.sxj.corejava.code11_io.字符流;

import java.io.*;

/**
 * @author 石小俊
 */
public class Test03_转换流 {

    public static void main(String[] args) {
        try (
//                FileInputStream in = new FileInputStream("hello.txt");
//                // 通过字节流获取对应的转换流
//                // 默认字符集
////                InputStreamReader reader = new InputStreamReader(in);
//                // 可以通过第二个参数指定字符集
//                InputStreamReader reader = new InputStreamReader(in, "GBK");
//                // 转换流只是用于将字节流转换成字符流的
//                // 实际的读写操作仍然需要通过字节流或者字符流实现
//                BufferedReader br = new BufferedReader(reader);

                // 简写方式
                BufferedReader br = new BufferedReader(
                        new InputStreamReader(
                                new FileInputStream("hello.txt"), "GBK"));

//                BufferedWriter writer = new BufferedWriter(
//                        new OutputStreamWriter(
//                                new FileOutputStream("bb.txt"),"GBK"));

                PrintWriter out = new PrintWriter("b.txt", "GBK");
        ) {
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
//                writer.write(line);
                out.println(line);
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
